/* ***********************************************************************
 * Copyright (C) 1992-2014 中国南方航空股份有限公司.
 *
 * Created [2014-5-5 下午3:10:40] by FMS Team
 * ***********************************************************************
 *
 * fms-udp
 * ***********************************************************************
 */
package com.foreveross.law.base.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.foreveross.law.base.dao.CrudRepository;
import com.foreveross.law.base.service.ICrudService;
import com.foreveross.law.common.util.GenericsUtils;

/**
 * <p>
 * com.csair.udp.common.service.impl.CrudServiceImpl.java
 * </p>
 * 
 * @author liaocw(mail)
 * @version $Revision$ $Date$
 * @Modified by liaocw(mail) description
 * @purpose add this file description here
 */
public abstract class CrudServiceImpl<T, ID extends Serializable> extends
		BaseServiceImpl<T> implements ICrudService<T, ID> {

	@Resource(name = "curdRepository")
	private CrudRepository<T, ID> crudRepository;

	/**
	 * @return the crudRepository
	 */
	public CrudRepository<T, ID> getCrudRepository() {
		return crudRepository;
	}

	/**
	 * @param crudRepository
	 *            the crudRepository to set
	 */
	public void setCrudRepository(CrudRepository<T, ID> crudRepository) {
		this.crudRepository = crudRepository;
	}

	/*
	 * @return
	 * 
	 * @see com.csair.udp.common.service.ICrudService#getEntityClass()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Class<T> getEntityClass() {
		return GenericsUtils.getSuperClassGenricType(getClass());
	}

	/*
	 * @param id
	 * 
	 * @return
	 * 
	 * @see com.csair.udp.common.service.ICrudService#get(java.io.Serializable)
	 */
	@Override
	public T get(Serializable id) {
		return this.getCrudRepository().get(getEntityClass(), id);
	}

	/*
	 * @param entity
	 * 
	 * @return
	 * 
	 * @see com.csair.udp.common.service.ICrudService#save(java.lang.Object)
	 */
	@Override
	public ID save(T entity) {
		return this.getCrudRepository().save(getEntityClass(), entity);
	}

	/*
	 * @param entity
	 * 
	 * @see com.csair.udp.common.service.ICrudService#update(java.lang.Object)
	 */
	@Override
	public void update(T entity) {
		this.getCrudRepository().update(getEntityClass(), entity);

	}

	/*
	 * @param id
	 * 
	 * @see
	 * com.csair.udp.common.service.ICrudService#delete(java.io.Serializable)
	 */
	@Override
	public void delete(ID id) {
		this.getCrudRepository().delete(getEntityClass(), id);

	}

	/*
	 * @return
	 * 
	 * @see com.csair.udp.common.service.ICrudService#findAll()
	 */
	@Override
	public List<T> findAll() {
		return this.getCrudRepository().findAll(getEntityClass());
	}
	
	/*
	 * @return
	 * 
	 * @see com.csair.udp.common.service.ICrudService#findAll(Map<String ,Object> param)
	 */
	@Override
	public List<T> findAll(Map<String ,Object> param) {
		return this.getCrudRepository().findAll(getEntityClass(),param);
	}

	/*
	 * @param parameter
	 * 
	 * @return
	 * 
	 * @see com.csair.udp.common.service.ICrudService#getCount(java.util.Map)
	 */
	@Override
	public long getCount(Map<String, ?> parameter) {
		return this.getCrudRepository().getCount(this.getEntityClass(),
				parameter);

	}
}
